﻿using System.Text.RegularExpressions;

public static partial class Utility
{

    /// <summary>
    /// 富文本格式化工具库
    /// </summary>
    public static class RichText
    {

        /// <summary>
        /// 格式化文本大小及颜色
        /// </summary>
        /// <param name="content">文本内容</param>
        /// <param name="size">文本大小</param>
        /// <param name="color">文本颜色</param>
        /// <returns></returns>
        public static string Formt(string content, int size, string color)
        {
            return Constant.Format.FONT_SIZE_COLOR_RICH_FORMAT.Format(content, size.ToString(), color);
        }

        /// <summary>
        /// 格式化文本大小
        /// </summary>
        /// <param name="content">文本内容</param>
        /// <param name="size">文本大小</param>
        /// <returns></returns>
        public static string FormatSize(string content, int size)
        {
            return Constant.Format.FONT_SIZE_RICH_FORMAT.Format(content, size.ToString());
        }

        /// <summary>
        /// 格式化文本颜色
        /// </summary>
        /// <param name="content">文本内容</param>
        /// <param name="color">文本颜色</param>
        /// <returns></returns>
        public static string FormatColor(string content, string color)
        {
            return Constant.Format.FONT_COLOR_RICH_FORMAT.Format(content, color);
        }

        /// <summary>
        /// 格式化为粗体文本
        /// </summary>
        public static string FormatBold(string content)
        {
            return Constant.Format.FONT_BOLD_RICH_FORMAT.Format(content);
        }

        /// <summary>
        /// 格式化为斜体文本
        /// </summary>
        public static string FormatItalic(string content)
        {
            return Constant.Format.FONT_ITALIC_RICH_FORMAT.Format(content);
        }

        static readonly Regex RICH_TEXT_REGEX = new Regex(@"<.*?>");

        /// <summary>
        /// 清理富文本
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string ClearRichText(string content)
        {
            return RICH_TEXT_REGEX.Replace(content, string.Empty);
        }
    }
}
